package com.qfedu.buy.api.api;

import com.qfedu.buy.api.service.AuthService;
import com.qfedu.buy.common.config.SystemConfig;
import com.qfedu.buy.common.dto.UserLoginDto;
import com.qfedu.buy.common.dto.UserOpDto;
import com.qfedu.buy.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: NeighborBuy
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-01-28 10:16
 */
@RestController
@RequestMapping("/api/auth/")
public class AuthApi {
    @Autowired
    private AuthService service;

    @GetMapping("/checkphone.do")
    public R checkPhone(@RequestParam String phone){
        return service.checkPhone(phone);
    }
    @GetMapping("/checktoken.do")
    public R checkToken(){
        return service.checkToken();
    }
    @PostMapping("/register.do")
    public R add(@RequestBody UserOpDto dto,HttpServletRequest request){
        dto.setIp(request.getHeader(SystemConfig.USER_IP));
        System.err.println(dto.getIp());
        return service.add(dto);
    }
    @PostMapping("/login.do")
    public R login(@RequestBody UserLoginDto dto,HttpServletRequest request){
        dto.setIp(request.getRemoteAddr());
        return service.login(dto);
    }
}
